/*
 * A121_app.h
 *
 *  Created on: 2023年4月25日
 *      Author: Administrator
 */
#include "main.h"


#define FIFO_NUB 100
union uf_union
{
	uint8_t   c[4];
	float     f;
};

union u32_union
{
	uint8_t   c[4];
	uint32_t  u32;
};
union u16_union
{
	uint8_t   c[2];
	uint16_t  u16;
};

union i16_union
{
	uint8_t   c[2];
	int16_t  i16;
};


//近距离保存校准数据和温度数据
typedef struct
{
	uint8_t    use_cal_caching_flag;
	uint8_t    cal_flag;
	uint8_t    close_buf[1500];
	uint16_t   close_buf_size;
	uint32_t   temp_buf[50];
	uint16_t   temp_buf_size;
	uint8_t    acc_recal;

} acc_cal_result_save_t;


typedef struct {
	float    start;//起始距离
	float    end;//长度
	uint16_t step_length;//为0是为自动步长
	uint8_t  profile;//为0时为自适应profile

	uint8_t  frame_idle;//帧间休眠
	uint16_t  hwaas;//硬件加速
	uint16_t  sweeps_per_frame;//扫描次数
	float     frame_rate;
	uint8_t   en_frame_rate;//控制使能
	uint8_t   en_reset_filters;//重置滤波器
	//帧内检测
	uint8_t   en_intra_detec_flag;//启用帧内检测
	float     intra_threshold;//帧内阈值
	float     intra_frame_time;//检测实时响应速度设置，响应慢减小，快加大
	float     intra_output_time;//帧内检测目标时信号不稳定则加大
    //帧间检测
	uint8_t   en_inter_detec_flag;//启用帧间检测
	float     inter_threshold;//帧内阈值
	float     inter_deviation;//低通滤波器 参数
	float     inter_fast_cutoff;//快速检测滤波参数
	float     inter_slow_cutoff;//慢速检测滤波参数
	float     inter_output_time;//帧间检测目标时信号不稳定则加大

	float     inter_frame_presence_timeout;//快速丢掉历史数据
	uint8_t   en_inter_phase_boost;//启动帧间相位检测

	uint16_t data_output_time;
	uint8_t  run_status;
	uint8_t  format;//0为字符格式主动推送，1为modbus
	uint8_t  ID;
	uint8_t  save_flag;//保存标志位
} A121_presence_config_t;



typedef struct {
	float    start;//起始距离
	float    end;//长度
	uint16_t step_length;//为0是为自动步长
	uint8_t  profile;//为0时为自适应profile  1~5

	uint8_t  reflector_shape;//反射面开关 0通用  1平面
	uint8_t  peak_sorting;//目标输出排序  0近到远，1为最强
	uint8_t  threshold_method;//阈值算法 0固定振幅(直线)  1固定强度（多段）  2记录 3 cfar
	uint16_t num_frames_recorded;//校准时使用的帧数 init=100
	float    threshold_sensitivity;//阈值灵敏度  0.5
	float    signal_quality;//信号质量 15
	uint8_t  close_cancellation;//近距离泄露抵消
	//以上为使用原厂算法时的参数
	//////////////////////////////////////
	uint8_t  average;//平均值
	uint8_t  scan_nub;//检测目标

	uint16_t  hwaas;//硬件加速
	uint8_t   gain;//接收增益  1~23
	uint16_t  sweeps_per_frame;//扫描次数
	float     sweep_rate;//扫描频率
	uint8_t   continuous_sweep_mode;//连续扫描设置
	uint16_t  threshold;
	float     frame_rate;


	uint8_t   frame_idle;//帧间休眠
	uint8_t   sweep_idle;//帧内休眠
	uint8_t   prf;//脉冲重复率
	uint8_t   phase_enhancemen_flag;//相位增强
	uint8_t   double_buffering_flag;//双重缓存

	uint16_t data_output_time;
	uint8_t  run_status;
	uint8_t  format;//0为字符格式主动推送，1为modbus
	uint8_t  ID;
	uint8_t  save_flag;//保存标志位
	uint8_t  printf_mode;//0为打印所有距离  1为打印波形 2为十六进制输出
} A121_distance_config_t;




typedef struct {
	float    Intra_detection_threshold;//
	float    Intra_time_constant;
	float    Intra_output_time_constant;
	float    Inter_detection_threshold;
	float    Inter_fast_cutoff_freq;
	float    Inter_slow_cutoff_freq;
	float    Inter_time_constant;
	float    Inter_output_time_constant;


}Breath_presence_t;

typedef struct {
	float    start;//起始距离
	float    end;//长度

	uint16_t step_length;
	uint16_t num_dists_to_analyze;//分析的距离点数
	float    distance_determination_duration;//秒
	uint8_t  use_presence_processor;//使用presence检测人体距离

	float lowest_breathing_rate;
	float highest_breathing_rate;
	float time_series_length_s;

	float     frame_rate;
	uint16_t  sweeps_per_frame;//扫描次数
	uint16_t  hwaas;//硬件加速
	uint8_t   profile;//为0时为自适应profile

	Breath_presence_t Breath_presence;


	float    start_m;//为0是为自动步长
	float    step_length_m;//为0是为自动步长
	uint16_t num_points;

	uint8_t  ID;
	uint8_t  format;//0为字符格式主动推送，1为modbus
	uint8_t  save_flag;//保存标志位

	uint8_t line;
	uint8_t  run_status;



} A121_breath_config_t;





